﻿#if UNITY_EDITOR


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;

namespace Assets.Scripts.Editor
{
    public class ApkBuilder
    {

        //在这里找出你当前工程所有的场景文件，假设你只想把部分的scene文件打包 那么这里可以写你的条件判断 总之返回一个字符串数组。
        static string[] GetBuildScenes()
        {
            List<string> names = new List<string>();
            foreach (EditorBuildSettingsScene e in EditorBuildSettings.scenes)
            {
                if (e == null)
                    continue;
                if (e.enabled)
                    names.Add(e.path);
            }
            return names.ToArray();
        }
        [MenuItem("Tools/BuildApk")]
        public static void ApkBuild()
        {
            string[] names = GetBuildScenes();
            PlayerSettings.Android.keyaliasName = "user";
            PlayerSettings.Android.keyaliasPass = "123456";
            PlayerSettings.Android.keystoreName = "user.keystore";
            PlayerSettings.Android.keystorePass = "123456";

            string path = Path.Combine(Application.dataPath, "../../apks/","and.apk");
            BuildPipeline.BuildPlayer(
                names,
                path,
                BuildTarget.Android,
                BuildOptions.None
            );
        }
    }
}
#endif